import com.can.dao.BlogMapper;
import com.can.pojo.Blog;
import com.can.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class test {

    SqlSession sqlSession = MybatisUtils.getSqlSessionTranIsTrue();

    @Test
    public void queryBlogIF(){
        BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class);
        Map<String,Object> parameter = new HashMap<String,Object>();
        HashMap map = new HashMap();
        parameter.put("title","java");
        parameter.put("author","can");
        List<Blog> blogList = blogMapper.queryBlogIF(parameter);
        for (Blog blog : blogList) {
            System.out.println(blog);
        }
        sqlSession.close();
    }

    @Test
    public void queryBlogChoose(){
        BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class);
        Map<String,Object> parameter = new HashMap<String,Object>();
        HashMap map = new HashMap();
//        parameter.put("title","java");
//        parameter.put("author","can");
        parameter.put("views","1000");
        List<Blog> blogList = blogMapper.queryBlogChoose(parameter);
        for (Blog blog : blogList) {
            System.out.println(blog);
        }
        sqlSession.close();
    }

    @Test
    public void updateBlogSet(){
        BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class);
        Map<String,Object> parameter = new HashMap<String,Object>();
        HashMap map = new HashMap();
        parameter.put("title","java");
        parameter.put("author","can");
        parameter.put("id","0ebe79345d6411eaa9f0aebd8b508cff");
       int result = blogMapper.updateBlog(parameter);
        System.out.println(result);
        sqlSession.close();
    }

    @Test
    public void queryBlogTrim(){
        BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class);
        Map<String,Object> parameter = new HashMap<String,Object>();
        HashMap map = new HashMap();
        parameter.put("title","java");
        parameter.put("author","can");
        List<Blog> blogList = blogMapper.queryBlogTrim(parameter);
        for (Blog blog : blogList) {
            System.out.println(blog);
        }
        sqlSession.close();
    }


    @Test
    public void queryBlogForeach(){
        BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class);
        Map<String,Object> parameter = new HashMap<>();
        ArrayList<String> ids = new ArrayList<>();
        ids.add("0ebe78215d6411eaa9f0aebd8b508cff");
        ids.add("0ebe79345d6411eaa9f0aebd8b508cff");

        parameter.put("ids",ids);
        List<Blog> blogList = blogMapper.queryBlogForeach(parameter);
        for (Blog blog : blogList) {
            System.out.println(blog);
        }
        sqlSession.close();
    }
}
